//============================================================================
// Name        : pexp_croath.cpp
// Author      : croath
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	void highlight();
	cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	highlight();
	return 0;
}

void highlight() {
	bool search_string_with_sql(char* string, int length);
	char buffer[40];
	char text[512] = "int a b c d e f g \"  adfd\" "; //color数组：普通－黑色1 高亮－紫色2 引号/头文件－蓝色3 注释－绿色4
	int color[512];
	int highlight_num = 0; //指向位置为text中最后一个未处理的字符串，如果全部处理完设为-1
	int length = 27;
	int buffer_num = 0;
	bool BLOCK_END = true;
	while (highlight_num != length) {

		if (text[highlight_num] == '\\') {
			color[highlight_num] = 3;
			color[highlight_num + 1] = 3;
			highlight_num++;
			continue;
		}
		if (text[highlight_num] == '\"') {
			if (BLOCK_END) {
				BLOCK_END = false;
			} else {
				BLOCK_END = true;
			}
			color[highlight_num] = 3;
			highlight_num++;
			continue;
		}
		if (text[highlight_num] >= 'a' && text[highlight_num] <= 'z') {
			if (!BLOCK_END) {
				color[highlight_num] = 3;
				highlight_num++;
			} else {
				buffer_num = 0;
				while (highlight_num + buffer_num <= length
						&& text[highlight_num + buffer_num] >= 'a'
						&& text[highlight_num + buffer_num] <= 'z') {
					buffer[buffer_num] = text[highlight_num + buffer_num];
					buffer_num++;
				}
				if (search_string_with_sql(buffer, buffer_num)) {
					for (int i = highlight_num; i < highlight_num + buffer_num;
							i++) {
						color[i] = 2;
					}
				} else {
					for (int i = highlight_num; i < highlight_num + buffer_num;
							i++) {
						color[i] = 1;
					}
				}
				highlight_num += buffer_num;
			}
			continue;
		}
		if (!BLOCK_END) {
			color[highlight_num] = 3;
		} else {
			color[highlight_num] = 1;
		}
		highlight_num++;

	}
	for (int i = 0; i < length; i++)
		printf("%d", color[i]);
	printf("\n");
	for (int i = 0; i < length; i++)
		printf("%c", text[i]);
}

bool search_string_with_sql(char* string, int length) {
	return true;
}
